
@{
    ViewBag.Title = "新增/编辑";
    Layout = "~/Areas/Admin/Views/Shared/_Layout_Edit.cshtml";
}
<form class="layui-form" method="post" action="/Admin/Adv/Save" id="myForm" autocomplete="off">
    <input type="hidden" value="@Model.Id" name="Id" />
    <input type="hidden" value="@Model.StartTime" name="StartTime" />
    <input type="hidden" value="@Model.EndTime" name="EndTime" />
    <input type="hidden" value="@Model.AdvImg" name="AdvImg" />
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red;">*</span>广告位</label>
                    <div class="layui-input-block">
                        <select class="layui-select" name="AdvPositionId" required lay-verify="required" autocomplete="off">
                            <option value="">--- 请选择广告位 ---</option>
                            @if (ViewBag.AdvPositionList != null)
                            {
                                foreach (var item in ViewBag.AdvPositionList)
                                {
                                    <option value="@item.Id" @(item.Id == Model.AdvPositionId ? "selected" : "")>@item.Name</option>
                                }
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red;">*</span>广告名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="AdvName" required lay-verify="required" autocomplete="off" class="layui-input" maxlength="128" value="@Model.AdvName">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red;">*</span>开始结束时间</label>
                    <div class="layui-input-block">
                        <input type="text" id="BeginEndTime" required lay-verify="required" autocomplete="off" class="layui-input" maxlength="12" value="@ViewBag.BeginEndTime">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">跳转Url</label>
                    <div class="layui-input-block">
                        <input type="text" name="JmpUrl" autocomplete="off" class="layui-input" maxlength="300" value="@Model.JmpUrl">
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" id="btnUpload1">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <img id="TitleImg" src="@Model.AdvImg" style="width:120px; margin-left:10px;@(Model.AdvImg + "" != "" ? "" : "display:none")" />
                    </div>
                </div>
                @*<div class="layui-form-item">
                        <label class="layui-form-label">发布状态</label>
                        <div class="layui-input-block">
                            <input type="checkbox" lay-filter="PulishStatus" value="@Model.PulishStatus" lay-skin="switch" lay-text="已发布|未发布" @(Model.PulishStatus == 1 ? "checked" : "")>
                        </div>
                    </div>*@
            </div>
        </div>
    </div>
    <div class="layui-footer">
        <button type="button" class="layui-btn layui-btn-primary" onclick="win.close()">关闭</button>
        <button type="button" class="layui-btn" lay-submit lay-filter="formSubmit">保存</button>
    </div>
</form>
@section Scripts{
    <script type="text/javascript">
        $(function () {
            layui.use('element', function () {
                var $ = layui.jquery, element = layui.element, laydate = layui.laydate;
            });
            layui.use('laydate', function () {
                var laydate = layui.laydate;
                //日期时间范围
                laydate.render({
                    elem: '#BeginEndTime'
                    , type: 'datetime'
                    , range: '~'
                    , done: function (value, date) {
                        var arr = value.split('~')
                        $('input[name=StartTime]').val(arr[0]);
                        $('input[name=EndTime]').val(arr[1]);
                    }
                });
            });
            layui.use('form', function () {
                var form = layui.form;
                form.verify($.verify);
                //监听提交
                form.on('submit(formSubmit)', function (data) {
                    win.showLoading("正在保存...");

                    var roleList = [];
                    roleList.push(parseInt($('#RoleId').val()));
                    $('input[name=UserRoleList]').val(JSON.stringify(roleList));

                    $("#myForm").ajaxSubmit(function (res) {
                        win.hideLoading();
                        if (res.code == 0) {
                            parent.getList();
                            parent.win.success("保存成功");
                            win.close();
                        } else {
                            win.alert(res.message);
                        }
                    });
                    return false;
                });
                form.on('switch(PulishStatus)', function (data) {
                    $('input[name=PulishStatus]').val(data.elem.checked ? 1 : 0);
                });
            });

            layui.use('upload', function () {
                var upload = layui.upload;
                var uploadInst1 = upload.render({
                    elem: '#btnUpload1'
                    , url: '/Admin/Upload/Upload'
                    , before: function (res) {
                        win.showLoading("正在上传...");
                    }
                    , done: function (res) {
                        if (res.code == 0) {
                            $("#TitleImg").show().attr("src", res.data[0].saveFilePath);
                            $("input[name='AdvImg']").val(res.data[0].saveFilePath);
                        } else {
                            win.alert("出错了");
                        }

                        win.hideLoading();
                    }
                    , error: function () {
                        win.hideLoading();
                        win.alert("出错了");
                    }
                });
            });
        });
    </script>
}

